package com.example.simalaya.base;

import android.app.Application;
import android.app.Notification;
import android.content.Context;
import android.os.Handler;

import com.example.simalaya.PlayerActivity;
import com.example.simalaya.utils.LogUtil;
import com.ximalaya.ting.android.opensdk.constants.DTransferConstants;
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest;
import com.ximalaya.ting.android.opensdk.player.XmPlayerManager;
import com.ximalaya.ting.android.opensdk.player.appnotification.XmNotificationCreater;

import org.xutils.x;


public class BaseApplication extends Application {

    private static Handler sHandler = null;

    private static Context sContext = null;

    @Override
    public void onCreate() {
        super.onCreate();

        x.Ext.init(this);
        CommonRequest mXimalaya = CommonRequest.getInstanse();
        if (DTransferConstants.isRelease) {
            String mAppSecret = "8646d66d6abe2efd14f2891f9fd1c8af";
            mXimalaya.setAppkey("9f9ef8f10bebeaa83e71e62f935bede8");
            mXimalaya.setPackid("com.app.test.android");
            mXimalaya.init(this, mAppSecret);
        } else {

            String mAppSecret = "ff31ae8153185db13b5f5393cae962c4";
            mXimalaya.setAppkey("be022ee6e9f19df55c4a6eb836b7b0b9");
            mXimalaya.setPackid("android.test");
            mXimalaya.init(this, mAppSecret);
        }

        //初始化播放器
       // XmPlayerManager.getInstance(this).init();
        Notification mNotification = XmNotificationCreater.getInstanse(this).initNotification(this.getApplicationContext(), PlayerActivity.class);
        XmPlayerManager.getInstance(this).init((int) System.currentTimeMillis(), mNotification);

        //初始化LogUtil
        LogUtil.init(this.getPackageName(),false);
        sHandler = new Handler();
        sContext = getBaseContext();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        //XmPlayerManager.release();
    }

    public static Context getAppContext() {
        return sContext;
    }

    public static Handler getHandler() {
        return sHandler;
    }



}
